<template>
  <div id="app">
    <div class="top">
      <div class="container">
        <div class="logo"></div>
        <h3>欢迎登录</h3>
        <a href="javascript:;" @click="goBack">进入官网首页<span>>></span></a>
      </div>
    </div>
    <div class="content">
      <div class="denglu">
        <nav>
          <a
            :class="{ active: 1 == isActive }"
            href="javascript:;"
            @click="zh(1)"
            >账户登录</a
          >
          <a
            :class="{ active: 2 == isActive }"
            class=""
            href="javascript:;"
            @click="sm(2)"
            >扫码登录</a
          >
        </nav>
        <div v-if="iszh">
          <div class="toggle">
            <a href="javascript:;"
              ><i class="iconfont icon-msg" d></i> 使用短信登录
            </a>
          </div>
          <input class="name" v-model="account" type="text" />
          <input class="word" v-model="password" type="password" />
          <div class="agree">
            <div class="xtx-checkbox" name="isAgree" value="true">
              <i class="iconfont icon-checked" data-v-51080bd3=""></i>
            </div>
            <span>我已同意</span>
            <a href="javascript:;">《隐私条款》</a>
            <span>和</span>
            <a href="javascript:;">《服务条款》</a>
          </div>
          <button @click="register()">登录</button>
        </div>
        <div class="sm" v-if="smd">
          <img
            src="http://erabbit.itheima.net/img/qrcode.5372a064.jpg"
            alt=""
          />
          <p>打开<a href="javascript:;">小兔鲜App</a>扫码登录</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'VueProject01Index',

  data() {
    return {
      account: 'xiaotuxian001',
      password: '123456',
      isActive: 1,
      iszh: true,
      smd: false,
    };
  },

  mounted() {},

  methods: {
    register() {
      if (this.account != '' && this.password != '') {
        this.axios
          .post('https://apipc-xiaotuxian-front.itheima.net/login', {
            account: this.account,
            password: this.password,
          })
          .then((res) => {
            if (res.data.msg == '操作成功') {
              // localStorage.setItem('token',res.data.result.token)
              this.$store.commit('userName', res.data.result);
              this.$store.commit('settoken', res.data.result.token);
              console.log(res.data.result.token);
              console.log(this.$store.state.userName);
              this.$router.push('/');
              this.$message({
                message: '登录成功',
                type: 'success',
              });
            }
          });
      }
    },
    goBack() {
      this.$router.go(-1);
    },
    zh(index) {
      this.isActive = index;
      this.iszh = true;
      this.smd = false;
    },
    sm(index) {
      this.isActive = index;
      this.iszh = false;
      this.smd = true;
    },
  },
};
</script>

<style scoped lang="scss">
.active {
  color: #27ba9b;
  font-weight: 700;
}
.top {
  width: 100%;
  height: 133px;
  .container {
    width: 1240px;
    height: 132px;
    margin: 0 auto;
    display: flex;
    .logo {
      width: 200px;
      height: 132px;
      background: url(http://erabbit.itheima.net/img/logo.0940ebb5.png)
        no-repeat center 18px / contain;
    }
    h3 {
      text-align: left;
      flex: 1;
      box-sizing: border-box;
      padding-top: 64px;
      font-size: 24px;
      font-weight: 400;
      margin-bottom: 38px;
      margin-left: 20px;
      color: #666;
    }
    a {
      padding-top: 68px;
      text-decoration: none;
      color: #333;
      outline: none;
      font-size: 16px;
      width: 120px;
      span {
        color: #27ba9b;
      }
    }
  }
}
.content {
  background: url(http://erabbit.itheima.net/img/login-bg.696efec3.png)
    no-repeat 50% / cover;
  height: 488px;
  position: relative;
}
.denglu {
  width: 380px;
  background: #fff;
  min-height: 400px;
  position: absolute;
  left: 50%;
  top: 54px;
  transform: translate3d(100px, 0, 0);
  box-shadow: 0 0 10px rgb(0 0 0 / 15%);
  display: flex;
  flex-direction: column;
  nav {
    height: 55px;
    border-bottom: 1px solid #f5f5f5;
    display: flex;
    padding: 0 40px;
    text-align: right;
    align-items: center;
    a {
      flex: 1;
      line-height: 1;
      display: inline-block;
      font-size: 18px;
      position: relative;
      &:nth-of-type(1) {
        border-right: 1px solid #f5f5f5;
        text-align: left;
      }
    }
  }
  .toggle {
    padding: 15px 40px;
    text-align: right;
  }
  .agree {
    .xtx-checkbox {
      display: inline-block;
      margin-right: 2px;
    }
    a {
      color: #069;
    }
  }
  input {
    font-size: 15px;
    margin: 15px auto;
    outline: none;
    box-sizing: border-box;
    padding-left: 44px;
    border: 1px solid #cfcdcd;
    height: 36px;
    line-height: 36px;
    width: 300px;
  }
  button {
    margin: 28px auto;
    border: none;
    outline: none;
    width: 300px;
    height: 40px;
    color: #fff;
    text-align: center;
    line-height: 40px;
    background: #27ba9b;
  }
}
</style>
